function islandPerimeter(grid: number[][]): number {
  let sum = 0
  const l1 = grid.length
  const l2 = grid[0].length
  for (let i = 0; i < l1; i += 1) {
    for (let j = 0; j < l2; j += 1) {
      if (grid[i][j]) {
        sum += grid[i][j - 1] ^ 1
        sum += (grid[i + 1] && grid[i + 1][j]) ^ 1
      }
    }
  }
  return sum << 1
}

export { islandPerimeter }
